/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.groupalpha.studentport;

import RSS.RSSFeed;
import RSS.RSSReader;
import RSS.RSSReaderException;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

/**
 * This example demonstrate the creation of a simple RSS feed reader using the XML adapter syntax.
 * The different elements of the feed are extracted using an {@link XmlDocumentProvider} and are
 * binded to the different views. An {@link OnItemClickListener} is also added, which will open a
 * browser on the associated news item page.
 */
public class LunchL extends Activity {
    private static final String FEED_URI = "http://cm.lskitchen.se/johanneberg/rss/";
    String hej ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	  requestWindowFeature(Window.FEATURE_NO_TITLE);

      	setContentView(R.layout.listviewtest);  
    	super.onCreate(savedInstanceState);
    	Bundle extras = getIntent().getExtras();
    	Button logoff = (Button) findViewById(R.id.button2);
    	final String url = extras.getString("URL");
    	String toastMsg = "Kunde inte ladda...";
        final ProgressDialog dialog = new ProgressDialog(LunchL.this);
    	dialog.setMessage("Laddar...");
        if(extras.getBoolean("Eng")){
    		logoff.setBackgroundResource(R.drawable.logoff_button_en);
    		toastMsg = "Could not load...";
    		dialog.setMessage("Loading...");
    	}
    	dialog.show();
    		final Toast toast = Toast.makeText(LunchL.this, toastMsg, Toast.LENGTH_SHORT);	
       final ListView list = (ListView) findViewById(R.id.listView1);
   
        final RSSReader reader = new RSSReader();
  //      String uri = "http://feeds.bbci.co.uk/news/world/rss.xml";
       
        	Thread th = new Thread(){
        		public void run(){
			final RSSFeed feed;
			try {
				feed = reader.load(url);
				LunchL.this.runOnUiThread(new Runnable(){
					public void run(){
						dialog.dismiss();
						list.setAdapter(new LunchAdapter(LunchL.this, feed.getItems()));
						
						
					}
					
					
				}
				);
				
				
			} catch (RSSReaderException e) {
				toast.show();
				Intent intent = new Intent(LunchL.this,
						LunchChoice.class);
				startActivity(intent);
				
			}
			 
        		}};
		th.start();
        

     //   getListView().setOnItemClickListener(new UrlIntentListener());
    }
}